home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-18 | 2.3 KB | 167 lines |
- // "Motion Shadow Effect"
-
- // created by ask@krc.sony.co.jp (Masamichi zzzcat Asukai)
-
- //
-
- // Copyright(C) 1996 Sony Corporation. All rights reserved.
-
- //
-
-
-
- import vrml.*;
-
- import vrml.node.*;
-
- import vrml.field.*;
-
-
-
- public class motion extends Script {
-
-
-
- private SFRotation setRotation;
-
- private SFVec3f setScale;
-
-
-
- private Node tree;
-
- private Node light;
-
-
-
- private float[] s_rot = {0.0f, 1.0f, 0.0f, 0.0f};
-
- private float[] s_scale = {1.0f, 1.0f, 1.0f};
-
-
-
- private float[] t_trans = new float[3];
-
- private float[] t_scale = new float[3];
-
- private float[] l_trans = new float[3];
-
-
-
- private float[] vec = new float[3];
-
- private float d;
-
-
-
- // constructor
-
- public void initialize() {
-
- setRotation = (SFRotation)getEventOut("setRotation");
-
- setScale = (SFVec3f)getEventOut("setScale");
-
-
-
- tree = (Node)((SFNode)getField("tree")).getValue();
-
- light = (Node)((SFNode)getField("light")).getValue();
-
-
-
- // get translation and scale of tree
-
- ((SFVec3f)tree.getExposedField("translation")).getValue(t_trans);
-
- ((SFVec3f)tree.getExposedField("scale")).getValue(t_scale);
-
- }
-
-
-
- public void processEvent(Event e) {
-
- if (e.getName().equals("interval")) {
-
- // get translation of light
-
- ((SFVec3f)light.getExposedField("translation")).getValue(l_trans);
-
-
-
- ////////////////////
-
- // SHADOW ROTATION
-
- ////////////////////
-
-
-
- // normalized light vector on X-Z plane
-
- vec[0] = t_trans[0] - l_trans[0];
-
- vec[2] = t_trans[2] - l_trans[2];
-
- d = (float)java.lang.Math.sqrt(vec[0]*vec[0] + vec[2]*vec[2]);
-
- vec[0] /= d;
-
- vec[2] /= d;
-
-
-
- // rotation of shadow
-
- if (vec[0] < 0.0) {
-
- s_rot[3] = (float)java.lang.Math.acos(-vec[2]);
-
- } else {
-
- s_rot[3] = -(float)java.lang.Math.acos(-vec[2]);
-
- }
-
-
-
- // set rotation of shadow
-
- setRotation.setValue(s_rot);
-
-
-
- ////////////////////
-
- // SHADOW LENGTH
-
- ////////////////////
-
-
-
- // whether light height is higher than top of tree
-
- if (l_trans[1] < t_scale[1]) {
-
- s_scale[2] = 0.0f;
-
- } else {
-
- s_scale[2] = d / (l_trans[1] - t_scale[1]);
-
- }
-
-
-
- // set length of shadow
-
- setScale.setValue(s_scale);
-
- }
-
- }
-
- }
-
-